package com.rj.framework.component.tech.captcha;

import lombok.Data;

import java.time.Duration;
import java.util.EnumMap;
import java.util.Map;

/**
 * 验证码配置
 */
@Data
public class CaptchaConfig {
    // 默认值
    private int defaultExpireMinutes = 5;
    private int smsCodeLength = 6;
    private int emailCodeLength = 6;
    private int imageCodeLength = 6;
    private int imageWidth = 120;
    private int imageHeight = 40;
    private int imageFontSize = 24;

    // 短信模板
    private String smsTemplate = "您的验证码是：{code}，有效期5分钟";

    // 邮件模板
    private String emailSubject = "您的验证码";
    private String emailTemplate = "您的验证码是：<strong>{code}</strong>，有效期5分钟";

    // 频率限制配置
    private Map<CaptchaType, Integer> rateLimit = new EnumMap<>(CaptchaType.class);
    private Map<CaptchaType, Duration> rateLimitPeriod = new EnumMap<>(CaptchaType.class);

    public CaptchaConfig() {
        // 默认频率限制：5次/分钟
        rateLimit.put(CaptchaType.SMS, 5);
        rateLimit.put(CaptchaType.EMAIL, 5);
        rateLimit.put(CaptchaType.IMAGE, 10);
        rateLimitPeriod.put(CaptchaType.SMS, Duration.ofMinutes(1));
        rateLimitPeriod.put(CaptchaType.EMAIL, Duration.ofMinutes(1));
        rateLimitPeriod.put(CaptchaType.IMAGE, Duration.ofMinutes(1));
    }
}